import { ArticleModel } from "../../../models/articleModel";

export interface ArticleAction {
    type: "SET_ARTICLEACTION",
    payload: ArticleModel,
}

export const article = (
    state: ArticleModel | undefined,
    action: ArticleAction
): ArticleModel => {
    if (!state) {
        return {
            id: 1,
            tags: ["c#", ".net"],
            title: "first article",
            summary: "",
            seen: 124,
            like: 31,
            content: `A paragraph with *emphasis* and **strong importance**.

            > A block quote with ~strikethrough~ and a URL: https://reactjs.org.
            
            * Lists
            * [ ] todo
            * [x] done
            
            A table:
            
            | a | b |
            | - | - |
            `,
            comments: [],
            date: "2020-1-1",
        }
    }
    switch (action.type) {
        case "SET_ARTICLEACTION":
            if (state.id === action.payload.id) {
                return state;
            }
            else {
                return action.payload;
            }
        default:
            return state;
    }
}